﻿@{
    Layout = null;
}
@model ElingOA6_Admin_DSJCJ.Model.SoftwareCatalog
<!DOCTYPE html>

<html>
@Html.Partial("LoadPanelPartial")
<head>
    <title>SoftwareCatalogContent</title>
      @if (false)
    {
        <script src="../../../../Scripts/jquery-vsdoc.js" type="text/javascript"></script>
        <script src="../../../../Scripts/ASPxScriptIntelliSense.js" type="text/javascript"></script>
    }
    <link href="@Url.Content("~/Content/Site.css", true)" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery.min.js", true)" type="text/javascript"></script>

    <script src="@Url.Content("~/Scripts/FloatDiv.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/regex.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/PageCommon.js", true)" type="text/javascript"></script>
    <script src="@Url.Content("~/Common/GetRootPath.ashx", true)" type="text/javascript"></script>

    @Html.DevExpress().GetStyleSheets(

        new StyleSheet { ExtensionType = ExtensionType.ListBox, Theme = DevExpressHelper.Theme },
                new StyleSheet { ExtensionType = ExtensionType.GridView, Theme = DevExpressHelper.Theme }
)
    @Html.DevExpress().GetScripts(
        new Script { ExtensionType = ExtensionType.ListBox }
)

    <script type="text/javascript">
        $(function () {
            $("#toolMenu").smartFloat();
        });

        function OnBeginCallback(s, e) {
            e.customArgs["command"] = e.command;
            e.customArgs["DeptNo"] = $('#hidDeptNo').val();
        }



        function MenuTop_emClick(source, e) {
            switch (e.item.name) {
                case "btnSave":
                    {


                        //保存

                        save();
                        break;
                    }
                case "btnAddSame":
                    {
                        //增同级
                        var clientCatalogIDObj = ASPxClientTextBox.Cast("FSoftwareCatalogID");
                        var catalogID = clientCatalogIDObj.GetText();
                        window.location.href = rootPath + "/Admin/SoftwareCatalog/SoftwareCatalogContent?catalogID=" + catalogID + "&addType=T";

                        break;
                    }
                case "btnAddNext":
                    {
                        //增下级
                        var clientCatalogIDObj = ASPxClientTextBox.Cast("FSoftwareCatalogID");
                        var catalogID = clientCatalogIDObj.GetText();

                        window.location.href = rootPath + "/Admin/SoftwareCatalog/SoftwareCatalogContent?catalogID=" + catalogID + "&addType=X";

                        break;
                    }
                case "btnDelete":
                    {
                        //删除
                        var clientCatalogIDObj = ASPxClientTextBox.Cast("FSoftwareCatalogID");
                        var catalogID = clientCatalogIDObj.GetText();
                        if (catalogID == "") {
                            alert("请选择删除的软件类别!");
                        } else {
                            if (confirm("确定删除?")) {
                                lpModal.Show();
                                $.ajax({
                                    type: 'POST',
                                    url: rootPath + '/Admin/SoftwareCatalog/DelCatalog',
                                    data: { catalogID: catalogID },
                                    success: function (result) {
                                        lpModal.Hide();
                                        if (result == "OK") {
                                            alert("删除成功");
                                            window.parent.location.href = rootPath + "/Admin/SoftwareCatalog";
                                        }
                                        else if (result == "EXISTCHILD") {
                                            alert("无法删除：存在下级软件类别，请先删除下级软件类别");
                                        }
                                        else if (result == "EXISTSOFT") {
                                            alert("无法删除：存在当前类别的软件，请先删除此类软件");
                                        }
                                        if (result == "ERROR") {
                                            alert("删除失败!");
                                        }
                                        if (result == "") {
                                            alert("参数错误");
                                        }
                                    }
                                });
                            }
                        }

                        break;
                    }
            }
        }

        //保存
        function save() {
            lpModal.Show();
            var addType = $('#hidAddType').val();
            var preID = $('#hidPreID').val();
            var clientCatalogIDObj = ASPxClientTextBox.Cast("FSoftwareCatalogID");
            var catalogID = 0;
            if (addType == "E") {
                catalogID = clientCatalogIDObj.GetText();
            }
            var clientCatalogNameObj = ASPxClientTextBox.Cast("FSoftwareCatalogName");
            var catalogName = clientCatalogNameObj.GetText();

            if (pd(catalogName)) {
                $.ajax({
                    type: 'POST',
                    url: rootPath + '/Admin/SoftwareCatalog/CatalogSave',
                    data: { addType: addType, preID: preID, catalogID: catalogID, catalogName: catalogName },
                    success: function (result) {
                        if (result == "ok") {
                            alert("保存成功");
                            if (addType == "E") {
                                parent.refreshNodeName(catalogName);
                                lpModal.Hide();
                            } else {
                                window.parent.location.href = rootPath+"/Admin/SoftwareCatalog";
                            }

                        } else if (result == "error") {
                            alert("保存失败");
                        } else {
                            alert("参数错误");
                        }
                    }
                });
            }
            else {
                lpModal.Hide();
            }
        }


        //判断
        function pd(catalogName) {
            var bl = true;
            if (catalogName == null || ASPxClientUtils.Trim(catalogName) == "") {
                FSoftwareCatalogName.SetErrorText("请填写软件种类名称");
                FSoftwareCatalogName.SetIsValid(false);
                bl = false;
            }


            return bl;
        }

    </script>

</head>
<body>
   @using (Html.BeginForm("Save", "SoftwareCatalog", FormMethod.Post, new { id = "form1", @class = "edit_form" }))
    { 
        <div class="floatToolMenu" id="toolMenu">
            @Html.DevExpress().Menu(settings =>
           {
               settings.Name = "toolBarMenu";
               settings.ItemAutoWidth = false;
               settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
               settings.Styles.Style.Border.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(0);
               settings.Styles.Style.BorderTop.BorderWidth = System.Web.UI.WebControls.Unit.Pixel(1);
               settings.Items.Add(item =>
              {
                  item.Name = "btnSave";
                  item.Text = "保存";
                  item.ClientEnabled = true;
                  item.Image.Url = Url.Content("~/Content/ControlImages/filesave.png");
          
              });
               settings.Items.Add(item =>
               {
                   item.Name = "btnAddSame";
                   item.Text = "增加同级";
                   item.ClientEnabled = true;
                   item.Image.Url = Url.Content("~/Content/ControlImages/addSame.png");
               
               });
               settings.Items.Add(item =>
               {
                   item.Name = "btnAddNext";
                   item.Text = "增加下级";
                   item.ClientEnabled = true;
                   item.Image.Url = Url.Content("~/Content/ControlImages/addNext.png");

               });
               settings.Items.Add(item =>
               {
                   item.Name = "btnDelete";
                   item.Text = "删除";
                   item.ItemStyle.ForeColor = System.Drawing.Color.Red;
                   item.ClientEnabled = true;
                   item.Image.Url = Url.Content("~/Content/ControlImages/cancel.png");

               });
               settings.ClientSideEvents.ItemClick = "function(source,e){MenuTop_emClick(source,e)}";
               settings.ItemLinkMode = ItemLinkMode.ContentBounds;
            }).GetHtml()
        </div>
 
        <table class="tableFrom">
            <tr>
                <th>
                    软件类别编号:
                </th>
                <td>
                    @Html.DevExpress().TextBox(settings =>
                    {
                        settings.Name = "FSoftwareCatalogID";
                        settings.Width = 200;
                        settings.Text = Model.FSoftwareCatalogID == 0 ? "待分配..." : Model.FSoftwareCatalogID.ToString();
                        settings.Enabled = false;
                        settings.Properties.ValidationSettings.EnableCustomValidation = true;
                    }).GetHtml()
                </td>
                <th>
                    软件类别名称:
                </th>
                <td>
                    @Html.DevExpress().TextBox(settings =>
                    {
                        settings.Name = "FSoftwareCatalogName";
                        settings.Width = 200;
                        settings.Text = Model.FSoftwareCatalogName;
                        settings.Properties.ValidationSettings.EnableCustomValidation = true;
                    }).GetHtml()
                </td>
            </tr>
        </table>
    
        @Html.Hidden("hidPreID", ViewData["preID"])
        @Html.Hidden("hidAddType",ViewData["addType"])
    }

    <script>
        lp.Hide();
    </script>

</body>
</html>
